#include <opencv/cv.h>

typedef struct
{
	CvPoint p0;
	CvPoint p1;

}Line;


class VanishPoint
{
	public:

	VanishPoint(void);
	~VanishPoint();

  void initialize(int imgWidth, int imgHeight);
	//setter functions, parameters
	void setCannyParams(unsigned int lowThresh, unsigned int highThresh, unsigned int gWindow);
	void setClasiffParams(float minAngleV, float maxAngleV, float minAngleH, float maxAngleH, float minDifAngle);
	void setHoughParams(int houghMethod, int minLineLength, double rhoRes, double angleRes, double param1, double param2, int maxLines);

	void process(IplImage* img, bool fidEnable);

	Line* getDetectedLines(void);
	int getLinesCount(void);
	CvPoint getVanishPoint(void);
	CvPoint* getCrossingPoints(void);
	int getCrossPointCount(void);
	IplImage* getCannyImg();


	private:

	//image parameters
	int imgWidth;
	int imgHeight;

	//Canny parameters
	int lowThresh;
	int highThresh;
	int gWindow;

	//line detection parameters
	int houghMethod;
	int minLineLength;
	double rhoRes;
	double angleRes;
	double param1;
	double param2;
	int maxLines;
	CvMemStorage* storage;
	CvSeq* hLines;

	//line clasification parameters
	//limits of line angles
	float minAngleV;
	float maxAngleV;
	float minAngleH;
	float maxAngleH;
	float minDifAngle;

	//points that define lines
	Line* lines;
	int validLines;

	//crossing points between lines
	CvPoint* crossingPoints;
	int crossCount;

	//the vanishing point
	CvPoint vp;
	//Fidelity of the vanishing point
	int fidelidad;

	//The image processed with Canny
	IplImage* canny;

	//canny function calculation
	IplImage* doCanny(
	    IplImage* in,
	    double     lowThresh,
	    double     highThresh,
	    double     aperture
	);

};
